package com.van.stockanalysis.service;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.van.stockanalysis.dao.UserDao;
import com.van.stockanalysis.pojo.User;

public class LoginService {
	public static boolean Login(String username,String password){
		String source = "mybatis-config.xml";
		InputStream inputstream = null;
		try {
			inputstream = Resources.getResourceAsStream(source);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(inputstream);
		SqlSession session = factory.openSession(); 
		
		UserDao userdao = session.getMapper(UserDao.class);
		User user = userdao.selectByUserName(username);
		if(user.getPassword().equals(password)){
			return true;
		}
		session.commit();
		session.close();
		return false;
	}
}
